package com.heima.controller;

import com.heima.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Collection;

@RestController
@RequestMapping("/ribbon")
public class RibbonController {
    @Value("${server.port}")
    String port;
    @Value("${dept.deptPath}")
    String deptPath;

    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/findAll")
    public Collection<Dept> findAll(){
        //因为ribbon通过注册中心的网关调用,可以将地址改为服务名
        return restTemplate.getForEntity("http://client/dept/findAll", Collection.class).getBody();
    }
    @GetMapping("/index")
    public String port(){
        return restTemplate.getForObject("http://client/dept/index",String.class );
    }
    

}
